package com.example.leoss.onclick_tmds;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.leoss.R;
import java.util.ArrayList;
import java.util.List;

public class MobanActivity extends AppCompatActivity implements View.OnClickListener {




     TextView qunfadown,tongxundown;
     FragmentAdapter fragmentAdapter;
     ViewPager viewPager;
     QunFaFragment qunFaFragment;
     TongxunDownFragment tongxunDownFragment;
     List<Fragment> list=new ArrayList<Fragment>();




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moban);


        init();
        setTitle("通讯录模板下载");
        fragmentAdapter=new FragmentAdapter(this.getSupportFragmentManager(),list);
         viewPager.setOffscreenPageLimit(2);
         viewPager.setAdapter(fragmentAdapter);
         viewPager.setCurrentItem(0);



        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position==0){
                    tongxundown.setTextColor(Color.parseColor("#0E0E0E"));//858383
                    qunfadown.setTextColor(Color.parseColor("#858383"));//0E0E0E

                    tongxundown.setBackground(new ColorDrawable(Color.parseColor("#F7F7F7")));//F7F7F7
                    qunfadown.setBackground(new ColorDrawable(Color.parseColor("#C3E0DADC")));//C3E0DADC

                }else if (position==1){

                    tongxundown.setTextColor(Color.parseColor("#858383"));
                    qunfadown.setTextColor(Color.parseColor("#0E0E0E"));

                    tongxundown.setBackground(new ColorDrawable(Color.parseColor("#C3E0DADC")));
                    qunfadown.setBackground(new ColorDrawable(Color.parseColor("#F7F7F7")));
                }


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }


    private void init() {
        qunfadown=findViewById(R.id.qunfadown);
        tongxundown=findViewById(R.id.tongxundown);
        tongxundown.setOnClickListener(this);
        qunfadown.setOnClickListener(this);

        viewPager=findViewById(R.id.mainViewPager);

        tongxunDownFragment=new TongxunDownFragment();
        qunFaFragment=new QunFaFragment();
        list.add(tongxunDownFragment);
        list.add(qunFaFragment);

    }
    @Override
    public void onClick(View v) {

        switch (v.getId()){

            case R.id.qunfadown:
                viewPager.setCurrentItem(1,true);
                break;
            case R.id.tongxundown:
                viewPager.setCurrentItem(0,true);
                break;
        }

    }





}
